package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursing_level")
@Api(tags = "护理等级管理")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> selectAll() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.selectAll();
        return ResponseResult.success(nursingLevelVos);
    }

    @PostMapping("/insert")
    @ApiOperation("添加护理等级")
    public ResponseResult insert(NursingLevelDto nursingLevelDto) {
        nursingLevelService.insert(nursingLevelDto);
        return ResponseResult.success();
    }

    @GetMapping("listByPage")
    @ApiOperation("分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(
            @ApiParam(value = "当前页码")
            @RequestParam(defaultValue = "1")
            Integer pageNum,

            @ApiParam(value = "每页显示条数")
            @RequestParam(defaultValue = "10")
            Integer pageSize,

            @ApiParam(value = "护理等级名称" )
            @RequestParam(required = false)
            String name,

            @ApiParam(value = "护理等级状态")
            @RequestParam(required = false)
            Integer status) {
        PageResponse<NursingLevelVo> page = nursingLevelService.selectByPage(pageNum, pageSize, name, status);
        return ResponseResult.success(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult<NursingLevelVo> selectById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.selectById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(NursingLevelDto nursingLevelDto) {
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult delete(@PathVariable Long id) {
        nursingLevelService.deleteById(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理等级状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.updateStatus(id, status);
        return ResponseResult.success();
    }
}


